package team.bailan.common.util;


import com.auth0.jwt.JWT;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

public class TokenUtil {

    public static int getTokenUserId() {
        String token = "31231243seascapes.dasdascsa.caxcaaxsa";// 从 http 请求头中取出 token

        if (JWT.decode(token).getAudience() == null) {
            return -1;
        }
        return Integer.parseInt(JWT.decode(token).getAudience().get(0));
    }

    /**
     * 获取request
     *
     * @return
     */
    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        return requestAttributes == null ? null : requestAttributes.getRequest();
    }
}


